using System;
using EmbeddedWebserver.Core;
using EmbeddedWebserver.Core.Handlers.Abstract;
using EmbeddedWebserver.Core.Json;
using SolarDevices.Configuration;

namespace SolarWeb
{
    class ScaleHandler : HandlerBase
    {

        #region Non-public members

        protected override void ProcessRequestWorker(HttpContext pContext)
        {
            switch (pContext.Request.Method)
            {
                case HttpMethods.GET:
                    pContext.Response.ContentType = "application/json";
                    var formatter = new JsonFormatter();
                    var solarConfig = new SolarConfiguration();
                    var scale = new GaugeScale
                        {
                            MaxPVVoltage = solarConfig.MaxPVVoltage,
                            PowerScale = solarConfig.PowerScale,
                            BatteryVoltageScale = solarConfig.BatteryVoltageScale
                        };
                    pContext.Response.ResponseBody = formatter.ToJson(scale);
                    break;
            }
        }

        #endregion

        #region Constructors

        public ScaleHandler()
            : base(HttpMethods.GET)
        {
        }

        #endregion
    }

    [Serializable]
    public class GaugeScale
    {
        public int MaxPVVoltage;
        public int PowerScale;
        public int BatteryVoltageScale;

    }
}